<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>单表管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		var articleSelect = [];
		function articleSelectAddOrDel(id,title){
			var isExtents = false, index = 0;
			for (var i=0; i<articleSelect.length; i++){
				if (articleSelect[i][0]==id){
					isExtents = true;
					index = i;
				}
			}
			if(isExtents){
				articleSelect.splice(index,1);
			}else{
				articleSelect.push([id,title]);
			}
			articleSelectRefresh();
		}
		function articleSelectRefresh(){
			$("#articleDataRelation").val("");
			$("#articleSelectList").children().remove();
			for (var i=0; i<articleSelect.length; i++){
				$("#articleSelectList").append("<li>"+articleSelect[i][1]+"&nbsp;&nbsp;<a href=\"javascript:\" onclick=\"articleSelectAddOrDel('"+articleSelect[i][0]+"','"+articleSelect[i][1]+"');\">×</a></li>");
				$("#articleDataRelation").val($("#articleDataRelation").val()+articleSelect[i][0]+",");
			}
		}
		$.getJSON("${ctx}/cms/article/findByIds",{ids:$("#articleDataRelation").val()},function(data){
			for (var i=0; i<data.length; i++){
				articleSelect.push([data[i][1],data[i][2]]);
			}
			articleSelectRefresh();
		});
		$("#relationButton").click(function(){
			top.$.jBox.open("iframe:${ctx}/cms/article/selectList?pageSize=8", "添加相关",$(top.document).width()-220,$(top.document).height()-180,{
				buttons:{"确定":true}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		});
		
		function save() {
			var basics = document.getElementById('basicss').checked;
			var professional  = document.getElementById('professionals').checked;
			var advanced = document.getElementById('advanceds').checked;
			if(basics) {
				document.getElementById("basics").setAttribute("value",1);
			} else {
				document.getElementById("basics").setAttribute("value",0);
			}
			if(professional) {
				document.getElementById("professional").setAttribute("value",1);
			} else {
				document.getElementById("professional").setAttribute("value",0);
			}
			if(advanced) {
				document.getElementById("advanced").setAttribute("value",1);
			} else {
				document.getElementById("advanced").setAttribute("value",0);
			}
			
		}
	</script>

</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/cloudfactory/cloudfactoryFunction/">功能表单</a></li>
		<li class="active"><a href="${ctx}/cloudfactory/cloudfactoryFunction/form?id=${cloudfactoryFunction.id}">功能添加</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="cloudfactoryFunction" action="${ctx}/cloudfactory/cloudfactoryFunction/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">菜单归属：</label>
			<div class="controls">
				<form:select path="functionType" class="input-medium">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('function_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">功能归属：</label>
			<div class="controls">
				<form:select path="menuId" class="input-medium">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('center_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">关键字：</label>
			<div class="controls">
				<form:input path="keyword" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">功能名称：</label>
			<div class="controls">
				<form:input path="functionName" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">功能类型：</label>
			<div class="controls">
				基础功能<input type="radio" name="isRequired" value="0"  checked/>
				选配功能<input type="radio"  name="isRequired" value="1"/>
			</div>
		</div>
		
		
		
		<div class="control-group">
			<label class="control-label">摘要：</label>
			<div class="controls">
				<form:input path="abstracts" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">产品概述:</label>
			<div class="controls">
				<form:textarea id="overview" htmlEscape="true" path="overview" rows="4" maxlength="800" class="input-xxlarge"/>
				<sys:ckeditor replace="overview" uploadPath="/cms/article" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">产品推荐：</label>
			<div class="controls">
				基础版：<input type="checkbox" name="basics" id="basics"   value="1"/>
				高级版：<input type="checkbox" name="advanced" id="advanced"   value="1"/>
				专业版：<input type="checkbox" name="professional" id="professional" value="1" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">图标:</label>
			<div class="controls">
                <input type="hidden" id="icon" name="icon" value="${cloudfactoryFunctory.icon}" />
				<sys:ckfinder input="image" type="thumb" uploadPath="/cms/article" selectMultiple="false"/>
			</div>
		</div>
		
		
		
		
		<div class="control-group">
			<label class="control-label">价格：</label>
			<div class="controls">
				<form:input path="money" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		
		
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" onclick="save()" type="submit" value="保 存并发布"/>&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>